﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Drawing;

namespace WFFS
{
    class Util{

        /// <summary> 
        /// 对图片进行处理,返回一个Image类别的对象 
        /// </summary> 
        /// <param name="oldImg">原图片</param> 
        /// <param name="newWidth">新图片宽度</param> 
        /// <param name="newHeight">新图片高度</param> 
        /// <returns></returns> 
        public static Image GetNewImage(Image oldImg, int newWidth, int newHeight)
        {
            Image newImg = oldImg.GetThumbnailImage(newWidth, newHeight, new Image.GetThumbnailImageAbort(IsTrue), IntPtr.Zero); // 对原图片进行缩放 
            return newImg;
        }
        private static bool IsTrue() // 在Image类别对图片进行缩放的时候,需要一个返回bool类别的委托 
        {
            return true;
        }
        //改变图片
        public static Image update_Size(Image memory, int oldWidth, int oldHeight)
        {
            //计算图片的比例，按新的大小缩放
            int width, height;
            if ((memory.Width / memory.Height) >= (oldWidth / oldHeight))
            {
                width = oldWidth;
                height = oldWidth * memory.Height / memory.Width;
                if (height > oldHeight)
                {
                    height = oldHeight;
                    width = oldHeight * memory.Width / memory.Height;
                }
            }
            else
            {
                height = oldHeight;
                width = oldHeight * memory.Width / memory.Height;
                if (width > oldWidth)
                {
                    width = oldWidth;
                    height = oldWidth * memory.Height / memory.Width;
                }
            }
            return GetNewImage(memory, width, height);
        }
    }
  
}
